{include file="common/header"}
<!-- 编辑器 -->
<script charset="utf-8" src="/admin_static/library/kindeditor/kindeditor-all-min.js"></script>
<script charset="utf-8" src="/admin_static/library/kindeditor/lang/zh-CN.js"></script>
<!-- <link rel="stylesheet" type="text/css" href="/admin_static/css/plugins/webuploader/webuploader.css">
<link rel="stylesheet" type="text/css" href="/admin_static/css/demo/webuploader-demo.min.css"> -->

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
       
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                   <div class="ibox-title">
                        <h5>商品添加</h5>
                        <span class="label label-primary pull-right label-primary-cust">
                            <a href="javascript:self.location=document.referrer;" class="fa-lg-cust-a" title="返回上一页">
                                <i class="fa fa-arrow-left fa-lg-cust"  aria-hidden="true"></i>
                            </a>
                        </span>
                    </div>
                    <div class="ibox-content">
                        <div class="alert alert-danger">
                            <b>警告：</b>封面图必须是宽350高350，商品图必须是宽750高350，详情图必须是宽750
                        </div>
                        <form class="form-horizontal m-t" id="partner" enctype="multipart/form-data">
                            <input type="hidden" name="goods_id" value="<?php echo $_GET['goods_id']; ?>">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">商品名称：</label>
                                <div class="col-sm-8">
                                    <input name="goods_name" type="text" value="<?php echo $res['goods_name'] ?>" class="form-control" required="" aria-required="true">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">商品分类：</label>
                                <div class="col-sm-8">
                                    <select class="form-control" name="type_id" id="type_id">
                                    <?php foreach($types as $key => $val): ?>
                                        <option <?php echo $res['type_id'] == $val['type_id']?'selected="selected"':''; ?> value="<?php echo $val['type_id'] ?>"><?php echo $val['type_name'] ?></option>
                                    <?php endforeach ?>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">商品库存：</label>
                                <div class="col-sm-8">
                                    <input name="goods_num" value="<?php echo $res['goods_num'] ?>" onkeyup="value=value.replace(/[^\d]/g,'')" type="number" class="form-control" required="" aria-required="true">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">销售价格：</label>
                                <div class="col-sm-8">
                                    <input name="price" type="text" value="<?php echo $res['price'] ?>" onkeyup="this.value=/^\d+\.?\d{0,2}$/.test(this.value) ? this.value : this.value.substring(0,this.value.length-1)" class="form-control" required="" aria-required="true">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">商品原价：</label>
                                <div class="col-sm-8">
                                    <input name="original_price" type="text" value="<?php echo $res['original_price'] ?>" onkeyup="this.value=/^\d+\.?\d{0,2}$/.test(this.value) ? this.value : this.value.substring(0,this.value.length-1)" class="form-control" required="" aria-required="true">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">一级返利（%）：</label>
                                <div class="col-sm-8">
                                    <input placeholder="如返1%，则只填写1" onkeyup="value=value.replace(/[^\d]/g,'')" name="p_return" type="number" value="<?php echo $res['p_return'] ?>" class="form-control" min="1" max="100" required="" aria-required="true">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">二级返利（%）：</label>
                                <div class="col-sm-8">
                                    <input placeholder="如返1%，则只填写1" onkeyup="value=value.replace(/[^\d]/g,'')" name="gp_return" type="number" value="<?php echo $res['gp_return'] ?>" class="form-control" min="1" max="100" required="" aria-required="true">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">首页显示：</label>
                                <div class="col-sm-8">
                                    <select class="form-control" name="is_show_home">
                                        <option <?php echo $res['is_show_home'] != 1?'selected="selected"':''; ?> value="0">否</option>
                                        <option <?php echo $res['is_show_home'] == 1?'selected="selected"':''; ?> value="1">是</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">商品描述：</label>
                                <div class="col-sm-8">
                                    <textarea name="describe" rows="2" class="form-control"><?php echo $res['describe'] ?></textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">封面图：</label>
                                <div class="col-sm-8">
                                    <img style="width:150px;height:150px;" src="<?php echo $res['goods_img']; ?>" alt="">
                                    <input type="file" name="image_first" class="form-control" aria-required="true">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">详情图：</label>
                                <div class="col-sm-8">
                                    <img style="height:150px;" src="<?php echo $res['goods_info']; ?>" alt="">
                                    <input type="file" name="goods_info" class="form-control" aria-required="true">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">商品图：</label>
                                <div class="col-sm-8">
                                    <div style="margin-top: 15px;">商品图 1 ：<img style="width:250px;height:150px;" src="<?php echo $goods_imgs[0]; ?>" alt=""> <input type="file" name="image1" class="form-control" aria-required="true"></div>
                                    <div style="margin-top: 15px;">商品图 2 ：<img style="width:250px;height:150px;" src="<?php echo $goods_imgs[1]; ?>" alt=""> <input type="file" name="image2" class="form-control" aria-required="true"></div>
                                    <div style="margin-top: 15px;">商品图 3 ：<img style="width:250px;height:150px;" src="<?php echo $goods_imgs[2]; ?>" alt=""> <input type="file" name="image3" class="form-control" aria-required="true"></div>
                                    <div style="margin-top: 15px;">商品图 4 ：<img style="width:250px;height:150px;" src="<?php echo $goods_imgs[3]; ?>" alt=""> <input type="file" name="image4" class="form-control" aria-required="true"></div>
                                    <div style="margin-top: 15px;">商品图 5 ：<img style="width:250px;height:150px;" src="<?php echo $goods_imgs[4]; ?>" alt=""> <input type="file" name="image5" class="form-control" aria-required="true"></div>
                                    <div style="margin-top: 15px;">商品图 6 ：<img style="width:250px;height:150px;" src="<?php echo $goods_imgs[5]; ?>" alt=""> <input type="file" name="image6" class="form-control" aria-required="true"></div>
                                </div>
                            </div>
                            <!-- <div class="form-group">
                                <label class="col-sm-3 control-label">商品图：</label>
                                <div class="col-sm-8">
                                    <div class="row">
                                        <div class="col-sm-12">
                                            <div class="ibox float-e-margins">
                                                <div class="ibox-content">
                                                    <div class="page-container">
                                                        <p>您可以尝试文件拖拽，或者点击添加图片按钮，来上传图片.</p>
                                                        <div id="uploader" class="wu-example">
                                                            <div class="queueList">
                                                                <div id="dndArea" class="placeholder">
                                                                    <div id="filePicker"></div>
                                                                    <p>或将照片拖到这里，单次最多可选7张</p>
                                                                </div>
                                                            </div>
                                                            <div class="statusBar" style="display:none;">
                                                                <div class="progress">
                                                                    <span class="text">0%</span>
                                                                    <span class="percentage"></span>
                                                                </div>
                                                                <div class="info"></div>
                                                                <div class="btns">
                                                                    <div id="filePicker2"></div>
                                                                    <div class="uploadBtn">开始上传</div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div> -->
                            <div class="form-group form-group-bottom">
                                <div class="col-sm-2 col-sm-offset-3">
                                    <p class="btn btn-primary" onclick="submitAdd();">确定修改</p>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            
            </div>
           
        </div>
    </div>
</body>
{include file="common/footer"}
<!-- <script type="text/javascript">
    var BASE_URL = '/admin_static/js/plugins/webuploader/index.html';
</script>
<script src="/admin_static/js/plugins/webuploader/webuploader.min.js"></script>
<script src="/admin_static/js/demo/webuploader-demo.min.js"></script> -->
<script>

    //按钮样式
    $(document).ready(function(){$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",})});

/*    //编辑器
    var editor;
    KindEditor.ready(function(K) {
        editor = K.create('textarea[name="content"]', {
            uploadJson : '/Admin/News/imagetext',
            fileManagerJson : '../jsp/file_manager_json.jsp',
            allowFileManager : true,
            resizeType:1
        });
    });*/

    //添加商品
    function submitAdd(){
        var formData = new FormData($('#partner')[0]);
        //var content;
        //var project_id = $('#type_id').attr('data-id');
        //formData.append('content',content);
        $.ajax({
            url: "/Admin/goods/edit",
            data:formData,
            type: "POST",
            dataType:'json',
            cache: false,//上传文件无需缓存
            processData: false,//用于对data参数进行序列化处理 这里必须false
            contentType: false, //必须
            success: function (d) {
                if(d){
                    if(d.error){
                        //console.log(d);
                        swal(d.msg, "", "error");
                        return false;
                }else{
                        swal(d.msg, "", "success");
                        setTimeout("window.location.href = '/admin/goods/list';",1000);
                    }
                }
            }
        })

    }
/*
    var uploader = WebUploader.create({  
      
        // swf文件路径  
        swf:  '/js/Uploader.swf',  
        formData:{"dn":$("#requestDn").val()},//参数列表  
        // 文件接收服务端。  
        server: '/admin/goods/update_img',  
        // 选择文件的按钮。可选。  
        // 内部根据当前运行是创建，可能是input元素，也可能是flash.  
        pick: '#filePicker',  
        // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！  
        resize: false,  
        // 只允许选择图片文件。  
        accept: {  
            title: 'file',  
            extensions: 'cer'  
    //                mimeTypes: '.cer,'  
        }  
    });  
    var $list = $("#dndArea");  
    uploader.on( 'fileQueued', function( file ) {  
        $list.append( '<div id="' + file.id + '" class="item">' +  
                '<h4 class="info">' + file.name + '</h4>' +  
                '<p class="state">等待上传...</p>' +  
                '<p class="progress progress-bar">上传进度...</p>' +  
                '</div>' );  
    });  
      
    uploader.on( 'uploadSuccess', function( file ) {  
        $( '#'+file.id ).find('p.state').text('已上传');  
    });

    uploader.on( 'error', function( handler ) { 

        //alert(handle); 
    });*/

</script>
